﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using SharpDB.DAO;

namespace SharpDB
{
    /// <summary>
    ///Create DAO
    /// </summary>
    public class DAOFactory
    {
        public static DAOBase CreateInstance(DBType dbType, string connectionString, bool checkStruct)
        {
            string _providerName = string.Empty;
            string _paramCharacter = string.Empty;
            DAOBase _DAOBase = null;
            switch (dbType)
            {
                case DBType.MsSql:
                    _providerName = "System.Data.SqlClient";
                    _paramCharacter = "@";
                    _DAOBase = new MSSqlDAO(DbProviderFactories.GetFactory(_providerName), dbType, connectionString, _paramCharacter, checkStruct);
                    break;
                case DBType.MySql:
                    _providerName = "MySql.Data.MySqlClient";
                    _paramCharacter = "@";
                    _DAOBase = new MySqlDAO(DbProviderFactories.GetFactory(_providerName), dbType, connectionString, _paramCharacter, checkStruct);
                    break;
                case DBType.Oracle:
                    _providerName = "System.Data.OracleClient";
                    _paramCharacter = ":";
                    break;
                case DBType.OracleManaged:
                    _providerName = "Oracle.ManagedDataAccess.Client";
                    _paramCharacter = ":";
                    break;
                case DBType.OracleDDTek:
                    _providerName = "DDTek.Oracle";
                    _paramCharacter = ":";
                    break;
                case DBType.Sqlite:
                    _providerName = "System.Data.SQLite";
                    _paramCharacter = "@";
                    break;
                default:
                    throw new ArgumentException("未知数据库类型类型！", "dbType");
            }
            if (_DAOBase == null)
            {
                //默认
                _DAOBase = new DAOBase(DbProviderFactories.GetFactory(_providerName), dbType, connectionString, _paramCharacter, checkStruct);
            }
            return _DAOBase;
        }
    }
}
